package com.zhuiYun.project.api.shoppingcart.controller;

import com.zhuiYun.project.api.shoppingcart.entity.ShoppingCartEntity;
import com.zhuiYun.project.api.shoppingcart.model.ShoppingCartModel;
import com.zhuiYun.project.api.shoppingcart.service.ShoppingCartService;
import com.zhuiYun.project.common.controller.BaseController;
import com.zhuiYun.project.common.errorCode.CommonException;
import com.zhuiYun.project.common.response.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @descriptions: ShoppingCartController
 * @Description 购物车
 * @author: zq
 * @date: 2023/4/5 17:03
 */
@RestController
@Api(tags = "购物车管理")
@RequestMapping("/shoppingCart")
@Slf4j
public class ShoppingCartController extends BaseController{
    @Resource
    ShoppingCartService shoppingCartService;
    /**
    * @Author 赵笛
    * @Description TODO 商品加入购物车
    * @Date 2023/4/6 20:06
    * @Return
    * @param shoppingCartModel
    */
    @PostMapping("/saveShoppingCart")
    @ApiOperation(value = "商品加入购物车的方法")
    public CommonResult saveShoppingCart(@RequestBody ShoppingCartModel shoppingCartModel) throws CommonException {
        log.info("商品加入购物车的方法");
        return shoppingCartService.saveShoppingCart(shoppingCartModel);
    }

    /**
     * @description: 用户查询购物车信息
     * @author: zq
     * @date: 2023/4/6 10:59
     * @param: [userId]
     * @return: com.zhuiYun.project.common.response.CommonResult
    **/
    @GetMapping("/shoppingCartByUserId")
    @ApiOperation(value = "购物车管理的用户查询购物车信息方法")
    public CommonResult shoppingCartByUserId(Integer userId) throws CommonException {
        log.info("用户查询购物车信息");
        CommonResult commonResult = shoppingCartService.shoppingCartByUserId(userId);
        return commonResult;
    }

    /**
     * @description: 用户查询购物车商品数量
     * @author: zq
     * @date: 2023/4/6 20:09
     * @param: [userId]
     * @return: com.zhuiYun.project.common.response.CommonResult
    **/
    @GetMapping("/shoppingCartCountByUserId")
    @ApiOperation(value = "购物车管理的用户查询购物车商品数量方法")
    public CommonResult shoppingCartCountByUserId(Integer userId) throws CommonException {
        log.info("用户查询购物车商品数量");
        CommonResult commonResult = shoppingCartService.shoppingCartCountByUserId(userId);
        return commonResult;
    }

    /**
     * @description: 用户修改购物车商品数量方法
     * @author: zq
     * @date: 2023/4/7 8:39
     * @param: [shoppingCartModel]
     * @return: com.zhuiYun.project.common.response.CommonResult
    **/
    @PutMapping("/changeNum")
    @ApiOperation(value = "购物车管理的用户修改购物车商品数量方法")
    public CommonResult changeNum(@RequestBody ShoppingCartModel shoppingCartModel) throws CommonException {
        log.info("用户修改购物车商品数量方法");
        CommonResult commonResult = shoppingCartService.changeNum(shoppingCartModel);
        return commonResult;
    }

    /**
     * @description: 用户删除购物车商品方法
     * @author: zq
     * @date: 2023/4/7 9:02
     * @param: [id]
     * @return: com.zhuiYun.project.common.response.CommonResult
    **/
    @DeleteMapping("/delShoppingCartByUserId")
    @ApiOperation(value = "购物车管理的用户删除购物车商品方法")
    public CommonResult delShoppingCartByUserId(Integer id) throws CommonException {
        log.info("用户删除购物车商品方法");
        CommonResult commonResult = shoppingCartService.delShoppingCartByUserId(id);
        return commonResult;
    }

    /**
     * @description: 用户删除选中购物车商品方法
     * @author: zq
     * @date: 2023/4/7 9:22
     * @param: [id]
     * @return: com.zhuiYun.project.common.response.CommonResult
    **/
    @PutMapping("/delShoppingCart")
    @ApiOperation(value = "购物车管理的用户删除选中购物车商品方法")
    public CommonResult delShoppingCart(@RequestBody List<Integer> listId) throws CommonException {
        log.info("用户删除选中购物车商品方法");
        CommonResult commonResult = shoppingCartService.delShoppingCart(listId);
        return commonResult;
    }

    /**
     * @description: 修改选中框状态为false
     * @author: zq
     * @date: 2023/4/7 9:22
     * @param: [id]
     * @return: com.zhuiYun.project.common.response.CommonResult
     **/
    @PutMapping("/wholeCheck")
    @ApiOperation(value = "购物车管理修改选中框状态为false方法")
    public CommonResult wholeCheck(@RequestBody List<Integer> ListId) throws CommonException {
        log.info("修改选中框状态为false方法");
        CommonResult commonResult = shoppingCartService.wholeCheck(ListId);
        return commonResult;
    }
    /**
     * @description: 修改选中框状态为true
     * @author: zq
     * @date: 2023/4/9 19:22
     * @param: [ListId]
     * @return: com.zhuiYun.project.common.response.CommonResult
    **/
    @PutMapping("/wholeChecks")
    @ApiOperation(value = "购物车管理修改选中框状态为true方法")
    public CommonResult wholeChecks(@RequestBody List<Integer> ListId) throws CommonException {
        log.info("修改选中框状态为true");
        CommonResult commonResult = shoppingCartService.wholeChecks(ListId);
        return commonResult;
    }

    /**
     * @description: 修改单选框状态为false
     * @author: zq
     * @date: 2023/4/10 15:35
     * @param: [id]
     * @return: com.zhuiYun.project.common.response.CommonResult
    **/
    @GetMapping("/checkboxById")
    @ApiOperation(value = "购物车管理修改单选框状态为false方法")
    public CommonResult checkboxById(Integer id) throws CommonException {
        log.info("修改单选框状态为false");
        CommonResult commonResult = shoppingCartService.checkboxById(id);
        return commonResult;
    }

    /**
     * @description: 修改单选框状态为true
     * @author: zq
     * @date: 2023/4/10 15:35
     * @param: [id]
     * @return: com.zhuiYun.project.common.response.CommonResult
     **/
    @GetMapping("/checkboxByIds")
    @ApiOperation(value = "购物车管理修改单选框状态为true方法")
    public CommonResult checkboxByIds(Integer id) throws CommonException {
        log.info("修改单选框状态为true");
        CommonResult commonResult = shoppingCartService.checkboxByIds(id);
        return commonResult;
    }
}
